﻿using System;

namespace Pfz.RemoteGaming.Internal
{
	internal struct _NotificationsDisablerForClient:
		IDisposable
	{
		private RemoteGameClient _client;
		private bool _oldNotificationsEnabled;
		public _NotificationsDisablerForClient(RemoteGameClient client)
		{
			_client = client;
			_oldNotificationsEnabled = client._notificationsEnabled;
			client._notificationsEnabled= false;
		}
		public void Dispose()
		{
			var client = _client;
			if (client == null)
				return;

			_client = null;
			if (_oldNotificationsEnabled)
			{
				client._notificationsEnabled = true;
				client._event.Set();
			}
		}
	}
}
